<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/5/24
 * Time: 14:10
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\business;


use app\common\lib\ArrClass;
use app\common\lib\Random;
use app\common\lib\sms\AliSms;
use think\facade\Cache;

class Sms extends BusBase
{
    public function sendCode(string $phone = '', string $type = 'ali')
    {
        //生成验证码
        $code = Random::randCode(4);
        $classStat = ArrClass::smsClassStat();
        $classObj = ArrClass::initClass($type, $classStat);
        $sms = $classObj::sendSms($phone, $code);
        if ($sms) {
            Cache::store('redis')->set(config('sms.code_pre_') . $phone, $code, "300");
            return true;
        } else {
            return false;
        }
    }
}